//防抖
export const debounce=(fn, delay) => {
  //记录上一次的延时器
  let timer = null;
  return () => {
    //清除上一次延时器
    clearTimeout(timer);
    //重新设置新的延时器
    timer = setTimeout(() => {
      fn()
    }, delay)
  }
};
//节流
export const throttle=(fn, delay) => {
  //记录上一次函数触发的时间
  let lastTime = 0;
  return () => {
    //记录当前函数触发的时间
    let nowTime = Date.now();
    if (nowTime - lastTime > delay) {
      fn();
      //同步时间
      lastTime = nowTime;
    }
  }
};
